package com.kuangjia.student_ems.dto;

import com.kuangjia.student_ems.entity.Attendance;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class AttendanceDTO {
    
    private Long id;
    private Long userId;
    private String userName;
    private Long departmentId;
    private String departmentName;
    private LocalDate date;
    private LocalDateTime checkInTime;
    private LocalDateTime checkOutTime;
    private Attendance.AttendanceStatus status;
    private String remark;
    private LocalDateTime createTime;
    
    // 签到位置相关字段
    private BigDecimal checkInLatitude;
    private BigDecimal checkInLongitude;
    private String checkInLocation;
    private String checkInAddress;
    private BigDecimal checkInAccuracy;
    private Attendance.LocationSource checkInLocationSource;
    private LocalDateTime checkInLocationTime;
    
    // 签退位置相关字段
    private BigDecimal checkOutLatitude;
    private BigDecimal checkOutLongitude;
    private String checkOutLocation;
    private String checkOutAddress;
    private BigDecimal checkOutAccuracy;
    private Attendance.LocationSource checkOutLocationSource;
    private LocalDateTime checkOutLocationTime;
    
    // 位置验证字段
    private Boolean locationVerified;
    private String locationVerificationNote;
    
    public static AttendanceDTO fromEntity(Attendance attendance) {
        AttendanceDTO dto = new AttendanceDTO();
        dto.setId(attendance.getId());
        dto.setUserId(attendance.getUser().getId());
        dto.setUserName(attendance.getUser().getName());
        dto.setDepartmentId(attendance.getUser().getDepartment().getId());
        dto.setDepartmentName(attendance.getUser().getDepartment().getName());
        dto.setDate(attendance.getDate());
        dto.setCheckInTime(attendance.getCheckInTime());
        dto.setCheckOutTime(attendance.getCheckOutTime());
        dto.setStatus(attendance.getStatus());
        dto.setRemark(attendance.getRemark());
        dto.setCreateTime(attendance.getCreateTime());
        
        // 设置地理位置信息
        dto.setCheckInLatitude(attendance.getCheckInLatitude());
        dto.setCheckInLongitude(attendance.getCheckInLongitude());
        dto.setCheckInLocation(attendance.getCheckInLocation());
        dto.setCheckInAddress(attendance.getCheckInAddress());
        dto.setCheckInAccuracy(attendance.getCheckInAccuracy());
        dto.setCheckInLocationSource(attendance.getCheckInLocationSource());
        dto.setCheckInLocationTime(attendance.getCheckInLocationTime());
        
        dto.setCheckOutLatitude(attendance.getCheckOutLatitude());
        dto.setCheckOutLongitude(attendance.getCheckOutLongitude());
        dto.setCheckOutLocation(attendance.getCheckOutLocation());
        dto.setCheckOutAddress(attendance.getCheckOutAddress());
        dto.setCheckOutAccuracy(attendance.getCheckOutAccuracy());
        dto.setCheckOutLocationSource(attendance.getCheckOutLocationSource());
        dto.setCheckOutLocationTime(attendance.getCheckOutLocationTime());
        
        dto.setLocationVerified(attendance.getLocationVerified());
        dto.setLocationVerificationNote(attendance.getLocationVerificationNote());
        
        return dto;
    }
} 